MemoryWriteStream: enforce single-flush semantics - #93
Merged
Conversation
Copilot created this pull request from a session on behalf of
Tyrrrz
July 24, 2026 11:09
View session
Tyrrrz
reviewed
Jul 24, 2026
…with Flush(bool) overload
Tyrrrz
approved these changes
Jul 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## prime #93 +/- ##
==========================================
+ Coverage 86.36% 86.51% +0.15%
==========================================
Files 78 78
Lines 1393 1409 +16
Branches 239 242 +3
==========================================
+ Hits 1203 1219 +16
Misses 137 137
Partials 53 53 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to enforce single-flush semantics in MemoryWriteStream, preventing repeated Flush() calls from silently re-copying the in-memory buffer into the underlying destination stream.
Changes:
- Track flush state in
MemoryWriteStreamand throw on subsequent manualFlush()calls. - Update disposal behavior to avoid throwing when
Dispose()triggers flush after a prior manual flush. - Add tests for double-flush throwing and flush-then-dispose not throwing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| PowerKit/MemoryWriteStream.cs | Adds flushed-state tracking and routes flush/dispose through a guarded path. |
| PowerKit.Tests/MemoryWriteStreamTests.cs | Adds tests for double-flush error behavior and flush-then-dispose behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Aug 1, 2026
This was referenced Aug 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MemoryWriteStream.Flush()could be called multiple times with no error, silently re-copying the buffer to the underlying stream on each call. It should only be flushed once.Changes
MemoryWriteStream: Added_flushedflag; subsequent manualFlush()calls throwInvalidOperationException. AddedDispose(bool)override that sets a_disposingguard before callingbase.Dispose()(which internally callsFlush()), so disposal after a prior manual flush is silently ignored. The guard is reset after disposal so that erroneousFlush()calls post-dispose still throw.MemoryWriteStreamTests: Two new tests covering the double-flush-throws and flush-then-dispose-ignores behaviors.